Skip to content

fix(sys): report host arch via IsWow64Process2 on Windows ARM64#705

Merged
timenick merged 3 commits into
mainfrom
fix/winml-sys-arm64-host-detection
May 22, 2026
Merged

fix(sys): report host arch via IsWow64Process2 on Windows ARM64#705
timenick merged 3 commits into
mainfrom
fix/winml-sys-arm64-host-detection

Conversation

@timenick
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes winml sys reports Machine: AMD64 on Windows ARM64 hosts #704winml sys showed Machine: AMD64 on Windows ARM64 hosts.
  • platform.machine() returns the process arch, so an x64 Python on ARM64 (under Prism emulation) misreports the host. PROCESSOR_ARCHITEW6432 is empty on Snapdragon X, so it's not a reliable fallback.
  • Added _get_windows_native_machine() using the Win32 IsWow64Process2 API to read the native machine type; falls back to platform.machine() if the call fails.
  • Added unit coverage for the emulation case and the fallback path; updated existing Windows tests to mock the new helper so they stay deterministic across host architectures.

Verification

  • winml sys on a Snapdragon X box now shows Machine: ARM64 (was AMD64).
  • uv run pytest tests/unit/sysinfo/test_sysinfo.py → 14 passed.
  • ruff check clean.

platform.machine() returns the process architecture, so an x64 Python
running under ARM64 emulation reports "AMD64" — the project venv hits
this because torch has no Windows-ARM64 wheel. PROCESSOR_ARCHITEW6432
is empty on Snapdragon X (Prism emulation does not set it), so detect
the native machine via IsWow64Process2 and fall back to platform.machine().
@timenick timenick requested a review from a team as a code owner May 22, 2026 04:18
@timenick timenick self-assigned this May 22, 2026
- Document that _IMAGE_FILE_MACHINE_TO_NAME is intentionally limited to
  the host architectures Windows 11 ships on (no 32-bit ARM, no IA64);
  unmapped values fall through to None and log at debug level.
- Log ctypes.get_last_error() when IsWow64Process2 returns 0 so a
  regression does not silently fall back to platform.machine().
- Hoist kernel32 + IsWow64Process2 to module scope, gated by
  sys.platform == "win32", so LoadLibrary runs once per process and
  non-Windows callers don't hit a ctypes.WinDLL error path.
- Add an explicit `if sys.platform != "win32": return None` guard in
  _get_windows_native_machine to match the pattern used in
  _preload_bundled_onnxruntime_dll (#689).
- Split the raw Win32 query (_query_native_machine_via_win32) from the
  name mapping (_get_windows_native_machine) and parametrize tests over
  IMAGE_FILE_MACHINE_* integers so a rename of "ARM64" → "Arm64" in the
  table fails the test instead of silently shipping.
Comment thread src/winml/modelkit/commands/sys.py Fixed
Comment thread src/winml/modelkit/commands/sys.py Fixed
CodeQL flagged "Module is imported with 'import' and 'import from'"
because the prior commit mixed `import ctypes as _ctypes` with
`from ctypes import wintypes as _wintypes`. Hoist `import ctypes` and
`import ctypes.wintypes` to the top of the module and reference the
qualified names; drop the function-local re-import of ctypes.
Copy link
Copy Markdown
Contributor

@xieofxie xieofxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you tested, just approved

@timenick timenick merged commit 0c4fb5a into main May 22, 2026
9 checks passed
@timenick timenick deleted the fix/winml-sys-arm64-host-detection branch May 22, 2026 05:20
DingmaomaoBJTU pushed a commit that referenced this pull request May 22, 2026
## Summary
- Fixes #704 — `winml sys` showed `Machine: AMD64` on Windows ARM64
hosts.
- `platform.machine()` returns the process arch, so an x64 Python on
ARM64 (under Prism emulation) misreports the host.
`PROCESSOR_ARCHITEW6432` is empty on Snapdragon X, so it's not a
reliable fallback.
- Added `_get_windows_native_machine()` using the Win32
`IsWow64Process2` API to read the native machine type; falls back to
`platform.machine()` if the call fails.
- Added unit coverage for the emulation case and the fallback path;
updated existing Windows tests to mock the new helper so they stay
deterministic across host architectures.

## Verification
- `winml sys` on a Snapdragon X box now shows `Machine: ARM64` (was
`AMD64`).
- `uv run pytest tests/unit/sysinfo/test_sysinfo.py` → 14 passed.
- `ruff check` clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

winml sys reports Machine: AMD64 on Windows ARM64 hosts

3 participants